package com.srit.identify.controller;

import com.srit.identify.common.IResponse;
import com.srit.identify.common.utils.JwtUtil;
import com.srit.identify.entity.UserInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AuthorizationController {

    @PostMapping("/authorize")
    public IResponse authorization(@RequestBody UserInfo userInfo){
        Map<String,Object> re = new HashMap<>();
        if (userInfo.verify()) {
            re.put("legality",1);
            re.put("authorization", JwtUtil.generateToken(userInfo.getUserId()));
        } else {
            re.put("legality",0);
        }
        return IResponse.success(re);
    }
    @GetMapping("/test")
    public IResponse tstr(String s){
        return IResponse.success(s);
    }

}
